package com.gqb.aop;

import java.lang.reflect.Method;
import java.util.List;

import net.sf.cglib.proxy.MethodProxy;


public class ProxyChain {
	private Class<?> clazz;
	private List<Proxy> proxyList;
	private Method method;
	private MethodProxy methodProxy;
	private Object target;
	private Object[] args;
	private int proxyIndex=0;
	private Object methodResult;
	public ProxyChain(Class<?> clazz,List<Proxy> proxyList, Method method,
			MethodProxy methodProxy, Object target, Object[] args) {
		super();
		this.proxyList = proxyList;
		this.method = method;
		this.methodProxy = methodProxy;
		this.target = target;
		this.args = args;
		this.clazz=clazz;
	}
	public Class<?> getClazz() {
		return clazz;
	}
	public Method getMethod() {
		return method;
	}
	public MethodProxy getMethodProxy() {
		return methodProxy;
	}
	public Object getTarget() {
		return target;
	}
	public Object[] getArgs() {
		return args;
	}
	public Object getMethodResult() {
		return methodResult;
	}
	
	public Object doProxyChain(){
		if(proxyIndex<proxyList.size()){
			proxyList.get(proxyIndex++).doProxy(this);
		}else{
			try {
				methodResult=methodProxy.invokeSuper(target, args);
			} catch (Throwable e) {
				 throw new RuntimeException(e);
			}
		}
		return methodResult;
	}
	
	
	
}
